package org.jfk.sys.dictionary;

import java.util.List;

import org.apache.log4j.Logger;
import org.jfk.core.controller.BaseController;
import org.jfk.sys.user.User;



public class DictTypeController extends BaseController {
	private static Logger logger = Logger.getLogger(DictTypeController.class);  
	
	public void add(){
		//super.redirect("/sys/dictionary/dictType/edit.jsp");
	}

	public void edit() {
		Object dictTypeId = getParaToInt();
		setAttr("dictType", DictType.dao.findById(dictTypeId));
		
		List<Dict> dictList = Dict.dao.queryDictByTypeId(dictTypeId);
		listColumns = new String[][] { 
				{ "id", "编号" },
				{ "dict_value", "值" }, 
				{ "status", "数据状态" }
				};

		super.setAttrs("dict_list_");		
		setAttr("dict_list_page",dictList);
	}

	public void save() throws Exception {
//		getModel(DictType.class).save();
		DictType dictType = getModel(DictType.class);
		if (dictType.get("id") == null){
			User currUser = super.getCurrUser();
			dictType.set("creator", currUser.getInt("id"));			
			
			dictType.save();
		}else{
			dictType.update();
		}
		super.renderJson();
	}
	
	public void list() {
		listColumns = new String[][] { 
				{ "id", "编号" },
				{ "enName", "英文名称" }, 
				{ "cnName", "中文名称" },
				{ "description", "数据字典类型描述" }, 
				{ "status_value", "数据状态" }, 
				{ "creator_loginName", "创建人" }
				};

		super.setAttrs();
		
		setAttr("page",DictType.dao.paginate(this));
		
	}
	
	public void del() {
		String id = getPara("id");
		DictType.dao.deleteById(id);
		super.renderText("test del");
	}

	public void delAll() {
		Integer[] checkedId = super.getParaValuesToInt("id[]");

		for (int i = 0; checkedId != null && i < checkedId.length; i++) {
			DictType.dao.deleteById(checkedId[i]);
		}
		super.renderText("test delAll");
	}
	
}
